package com.itheima.config;

import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.mapper.MapperScannerConfigurer;
import org.springframework.context.annotation.Bean;

import javax.sql.DataSource;

/**
 * mybatis的配置类
 */
public class MyBatisConfig {
    @Bean
    //创建一个方法获取SqlSessionFactoryBean对象
    public SqlSessionFactoryBean getSqlSessionFactoryBean(DataSource dataSource){
        SqlSessionFactoryBean sfb = new SqlSessionFactoryBean();
        sfb.setDataSource(dataSource);
        sfb.setTypeAliasesPackage("com.itheima.domain");
        return sfb;
    }
    //同上,注解开启持久层o
    @Bean
    public static MapperScannerConfigurer getMapper(){
        MapperScannerConfigurer msc = new MapperScannerConfigurer();
        msc.setBasePackage("com.itheima.mapper");
        return msc;
    }
}
